IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'SagasGet')
	BEGIN
		DROP  Procedure  SagasGet
	END

GO

CREATE Procedure SagasGet
@CreatorID int = NULL
AS
IF(@CreatorID IS NULL)
BEGIN
	SELECT 
	SagaID,
	TemplateStyle,
	Name,
	TagLine,
	Header,
	CurrentAffairs,
	SagaSummary,
	FormationStory,
	CurrentYear,
	DATENAME(month, CONVERT(DATETIME, CONVERT(nvarchar,FoundedMonth) + '/1/2000') ) + ' ' + CONVERT(nvarchar, FoundedYear) + ' A.D.' as FoundedDate
FROM Saga 
END
ELSE
BEGIN
	SELECT 
		s.SagaID,
		s.TemplateStyle,
		s.Name,
		s.TagLine,
		s.Header,
		s.CurrentAffairs,
		s.SagaSummary,
		s.FormationStory,
		s.CurrentYear,
		DATENAME(month, CONVERT(DATETIME, CONVERT(nvarchar,FoundedMonth) + '/1/2000') ) + ' ' + CONVERT(nvarchar, FoundedYear) + ' A.D.' as FoundedDate
	FROM Saga s
	Join 
	SagaCreators sc On sc.SagaID = s.SagaID 
	Where sc.CreatorID = @CreatorID
END 

GO



